export default {
    namespaced: true,
    state: {
        phoneList: [],
    },
    mutations: {
        //添加到购物车列表
        addPhoneList(state, val) {
            if (state.phoneList.findIndex((item, index) => {
                //如果存在且参数相同则数量++
                console.log(state.phoneList);
                if((item.id === val.id) && (item.other.color === val.other.color) && (item.other.memory === val.other.memory)) {
                    console.log('shoppingcartjs',item.other.color,val.other.color);
                    state.phoneList[index].num++
                    return true
                }
               
            })!== -1) {
                return
            }
            //商品不存在则添加
            val.num = 1
            state.phoneList.push(val)
        },

        //删除一条数据
        delPhoneList(state, val) {
          state.phoneList.splice(val,1)
        }
        
    }
}